package com.hxd.otc.dialog;

import android.content.Context;
import android.view.Gravity;
import android.view.View;

import com.flyco.dialog.widget.popup.base.BasePopup;
import com.hxd.otc.utils.NotchHelper;

/**
 * Created by lzy on 2018/11/20 0020.
 * description ${TODO}
 */
public abstract class BasePopupWindow<T extends BasePopupWindow<T>> extends BasePopup<T> {
    public BasePopupWindow(Context context) {
        super(context);
    }

    @Override
    public T anchorView(View anchorView) {
        if (anchorView != null) {
            mAnchorView = anchorView;
            int[] location = new int[2];
            mAnchorView.getLocationOnScreen(location);
            mAnchorView.getLocationInWindow(location);

            mX = location[0];

            int notchHeight = NotchHelper.getPopupWindowCorrectHeight();

            if (mGravity == Gravity.TOP) {
                mY = location[1] - notchHeight;
            } else {
                mY = location[1] - notchHeight + anchorView.getHeight();
            }
        }
        return (T) this;
    }
}
